<?php
/**
 * Created by PhpStorm.
 * User: VJLau
 * Date: 2018/2/5
 * Time: 下午12:29
 */

$id = intval($_GPC['id']);
$adult_number = intval($_GPC['adult_number']);
$child_number = intval($_GPC['child_number']);
$baby_number = intval($_GPC['baby_number']);
$date = trim($_GPC['date']);
$type = trim($_GPC['type']);
$sku_id = intval($_GPC['sku_id']);
$member = unserialize(base64_decode($_SESSION['vj_member']));
if (empty($id)) message('参数错误', $this->createMobileUrl('list'), 'error');
if ($adult_number == 0 && $child_number == 0 && $baby_number == 0) message('请选择人数', $this->createMobileUrl('list'), 'error');
if (empty($date)) message('请选择时间', $this->createMobileUrl('list'), 'error');
switch ($type) {
    case "single":
        $goods = pdo_fetch("SELECT sg.*,currency.exchange_rate FROM " . tablename('bontrip_single')
            . " AS sg LEFT JOIN " . tablename('bontrip_currency') . " AS currency ON currency.id = sg.currency_id WHERE sg.id = '{$id}' and sg.deleted_at is null");
        break;
    case "oneday":
        $goods = pdo_fetch("SELECT od.*,currency.exchange_rate FROM " . tablename('bontrip_oneday')
            . " AS od LEFT JOIN " . tablename('bontrip_currency') . " AS currency ON currency.id = od.currency_id WHERE od.id = '{$id}' and od.deleted_at is null");
        break;
    case "quality":
        $goods = pdo_fetch("SELECT ql.*,currency.exchange_rate FROM " . tablename('bontrip_quality')
            . " AS ql LEFT JOIN " . tablename('bontrip_currency') . " AS currency ON currency.id = ql.currency_id WHERE ql.id = '{$id}' and ql.deleted_at is null");
        break;
    default:
        message('参数错误', $this->createMobileUrl('list'), 'error');
        break;
}
if (empty($goods)) message('商品不存在或已下架', $this->createMobileUrl('list'), 'error');

if (!empty($sku_id)) {
    $sku = pdo_fetch("select * from " . tablename('bontrip_sku')
        . " where id={$sku_id} and deleted_at is null");
    if (empty($sku))
        message('sku参数不存在', $this->createMobileUrl('list'), 'error');
}

//出游人数
$tour_str = '';
if ($adult_number != 0) {
    $tour_str .= $adult_number . '成人';
    $adult = range(1, $adult_number);
}
if ($child_number != 0) {
    $tour_str .= $child_number . '儿童';
    $child = range(1, $child_number);

}
if ($baby_number != 0) {
    $tour_str .= $baby_number . '婴儿';
    $baby = range(1, $baby_number);

}

//计算金额
$goods['adult_price'] = round($goods['adult_price'] * $goods['exchange_rate']);
$goods['child_price'] = round($goods['child_price'] * $goods['exchange_rate']);
$goods['baby_price'] = round($goods['baby_price'] * $goods['exchange_rate']);

$goods['total_amount'] = number_format(($adult_number * $goods['adult_price']) + ($child_number * $goods['child_price']) + ($baby_number * $goods['baby_price']), 2);

$title = '订单详情';
include $this->template('payment');
